package com.lap.auth.domain.user.service;

import com.lap.auth.domain.role.Role;
import com.lap.auth.domain.role.repository.RoleRepository;
import com.lap.auth.shared.errors.UserError;
import com.lap.framework.common.exception.BizException;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

@RequiredArgsConstructor
public class UserRoleValidator {

  private final RoleRepository roleRepository;

  public void validateRolesExist(Set<Integer> roleSet) {
    if (CollectionUtils.isEmpty(roleSet)) {
      return;
    }

    List<Role> roles = roleRepository.findByIds(roleSet);
    if (roleSet.size() != roles.size()) {
      BizException.interrupt(UserError.USER_ROLE_NOT_MATCH);
    }
  }
}
